import request from '@/utils/request'
import { ObjectType, ResponseDataPromise } from 'typings/interfaces'
import * as proxy from '@/constants/proxy'
import { Pagination } from '@/components/Records/types'

export const fetchRecordsRequest = (
  pagination: Omit<Pagination, 'total'>,
  data: ObjectType
): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-other-asserts/page',
    method: 'post',
    params: pagination,
    data,
  })

export const createRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-other-asserts',
    method: 'post',
    data,
  })


export function getRecordRequest(id: any): Promise<any> {
  return request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-other-asserts/${id}`,
    method: 'get',
  })
}

export const editRecordRequest = (data: ObjectType): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-other-asserts',
    method: 'patch',
    data,
  })


export const deleteRecordsRequest = (ids: string[]) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-other-asserts`,
    method: 'delete',
    data: ids,
  })

export const lockRecordRequest = (id: string, lock: 0 | 1) =>
  request({
    url: proxy.CHECC_API_BASE_DATA + `/bd-other-asserts/lock`,
    method: 'post',
    data: {
      id,
      lock
    },
  })


export const exportRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-other-asserts/export',
    method: 'post',
  })

export const importRecordsRequest = (): ResponseDataPromise<ObjectType> =>
  request({
    url: proxy.CHECC_API_BASE_DATA + '/bd-other-asserts/import',
    method: 'post',
  })

